<?php

namespace app\apicompany\controller;

use app\common\controller\Api;
use think\Config;
use think\Exception;

/**
 * 职位表
 */
class PersonagePost extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    protected $failException = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\api\model\PersonagePost();
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }

    }


    /**
     * 列表
     * @return void
     */
    public function list()
    {
        try {
            $data = $this->model->select();
            $data =  getInfinitus($data->toArray());
            $this->success('ok', $data);
        }catch (Exception $e) {
            $this->error($e->getMessage());
        }
    }
    
    
     /**
     * 保存
     * @return void
     */
    public function save(){
        $input = input('post.');
        try {
            if(!empty($input['id'])){
                $id = $input['id'];
                unset($input['id']);
                $this->model->where('id',$id)->update($input);
            }else {
                // $input['user_id'] = $this->auth->getUser()['id'];
                $input['createtime'] = time();
                $this->model->insert($input);
            }

            $this->success('保存成功');
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
    }


    /**
     * 删除
     * @return void
     */
    public function del(){
        $input = input('post.');
        try {
           $this->model->where('id',$input['id'])->delete();
            $this->success('ok');
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
    }

}